#include "../stdafx.h"
#include "LightManager.h"

CLightManager::CLightManager()
{
	m_lights.clear();
	m_ambientLight[0] = 0.1;
	m_ambientLight[1] = 0.1;
	m_ambientLight[2] = 0.3;
	m_ambientLight[3] = 1.0;
	CLight light;
	light.SetLightParas(NULL, NULL, NULL);
	AddNewLight(light);
}


void CLightManager::SetAmbientLight(float ambLight[])
{
	if (ambLight)
	{
		for (int i = 0; i < 4; i++)
			m_ambientLight[i] = ambLight[i];
	}
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, m_ambientLight);
}

void CLightManager::EnableAllLights()
{
	glEnable(GL_LIGHTING);
	vector<CLight>::iterator it;
	for (it = m_lights.begin(); it != m_lights.end(); it++)
	{
		glEnable(GL_LIGHT0 + it->GetLightIndex());
	}
}

void CLightManager::DisableAllLights()
{
	glDisable(GL_LIGHTING);
	vector<CLight>::iterator it;
	for (it = m_lights.begin(); it != m_lights.end(); it++)
	{
		glDisable(GL_LIGHT0 + it->GetLightIndex());
	}
}